package com.efuture.androidmvvmdemo.view.ui

import android.os.Bundle
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import com.efuture.androidmvvmdemo.R
import com.efuture.androidmvvmdemo.base.BaseActivity
import com.efuture.androidmvvmdemo.databinding.ActivityRegisterBinding
import com.efuture.androidmvvmdemo.listener.RegisterListener
import com.efuture.androidmvvmdemo.viewmodel.RegisterViewModel

class RegisterActivity : BaseActivity() {
    private lateinit var  binding: ActivityRegisterBinding
    private lateinit var registerViewModel: RegisterViewModel
    private lateinit var registerListener:RegisterListener
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar?.hide()
        binding = DataBindingUtil.setContentView(this,R.layout.activity_register)
        registerViewModel = ViewModelProvider(this).get(RegisterViewModel::class.java)
        registerListener = RegisterListener(registerViewModel,this)
        click()
        observeData()

    }
    private fun click() {
        binding.btRegister.setOnClickListener {
            registerListener.registerUser(binding.etUsername.text.toString(),binding.etPassword.text.toString())
        }
    }
    private fun observeData() {
        registerViewModel.registerUserData.observe(this,{
            registerListener.dealRegisterResult(it)
        })
    }


}